package com.recharge.controller.callback;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.recharge.OrderService;
import com.recharge.domain.TradeFlow;
import com.recharge.domain.TradeOrder;
import com.recharge.mapper.ITradeFlowMapper;
import com.recharge.mapper.ITradeOrderMapper;
import com.recharge.sup.AbsSupChargeService;

@Controller
@RequestMapping("/quxun")
public class QuXunCallBankController {
	private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ITradeOrderMapper iTradeOrderMapper;

    @Autowired
    private ITradeFlowMapper iTradeFlowMapper;

    @Autowired
    private OrderService orderService;

    @Resource(name = "quXunChargeServiceImpl")
    private AbsSupChargeService absSupChargeService;
    
    @RequestMapping("/callback")
    @ResponseBody
    public String quXun(@RequestParam("order_id")String order_id ,
                              @RequestParam("transactionid")String transactionid ,
                              @RequestParam("orderstatus")String orderstatus ,
                              @RequestParam("plat_offer_id")String plat_offer_id,
                              @RequestParam("facevalue")String facevalue ,
                              @RequestParam("phone_id")String phone_id,
                              @RequestParam("ordertime")String ordertime ,
                              @RequestParam("result_code")String result_code ){
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("order_id", order_id);
        paramMap.put("transactionid", transactionid);
        paramMap.put("orderstatus", orderstatus);
        paramMap.put("plat_offer_id", plat_offer_id);
        paramMap.put("facevalue", facevalue);
        paramMap.put("phone_id", phone_id);
        paramMap.put("ordertime", ordertime);
        paramMap.put("result_code", result_code);
        
        logger.info("orderID:{},收到结果回调,返回信息code:{}",order_id,orderstatus);
        
        
        TradeOrder tradeOrder =iTradeOrderMapper.selectByOrderId(order_id);
        TradeFlow tradeFlow = iTradeFlowMapper.selectByOrderId((short) 2, order_id);
        absSupChargeService.response(tradeOrder,tradeFlow,paramMap);

        return "1";
    }
}
